package com.qys.livesMall.shop.controller.app;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qys.livesMall.common.result.R;
import com.qys.livesMall.common.utils.EnumListUtil;
import com.qys.livesMall.framework.utils.SecurityUtils;
import com.qys.livesMall.shop.constants.ShopSellTaskStatus;
import com.qys.livesMall.shop.modal.dto.task.app.SellTaskShopPageDTO;
import com.qys.livesMall.shop.modal.dto.task.app.ShopSellTaskSaveDTO;
import com.qys.livesMall.shop.modal.vo.task.app.SellTaskDetailVo;
import com.qys.livesMall.shop.modal.vo.task.app.SellTaskSettlementDetailVo;
import com.qys.livesMall.shop.modal.vo.task.app.SellTaskShopPageVo;
import com.qys.livesMall.shop.service.H2ShopBaseService;
import com.qys.livesMall.shop.service.ShopSellTaskService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 店铺带货任务表 前端控制器
 * </p>
 *
 * @author
 * @since 2023-06-15
 */
@RestController
@Tag(name = "APP-带货任务")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RequestMapping("/app/shop/sell/task")
public class AppShopSellTaskController {


    private final ShopSellTaskService shopSellTaskService;
    private final H2ShopBaseService h2ShopBaseService;


    @PostMapping("/releaseTask")
    @Operation(summary = "发布带货任务")
    public R<Void> releaseTask(@RequestBody @Validated ShopSellTaskSaveDTO saveDTO) {
        shopSellTaskService.releaseTask(saveDTO);
        return R.ok();
    }

    @PutMapping("/updateTask")
    @Operation(summary = "修改带货任务")
    public R<Void> updateTask(@RequestBody @Validated ShopSellTaskSaveDTO saveDTO) {
        shopSellTaskService.updateTask(saveDTO);
        return R.ok();
    }

    @PostMapping("/sellTaskPage")
    @Operation(summary = "分页查询带货任务列表")
    public R<Page<SellTaskShopPageVo>> sellTaskPage(@RequestBody SellTaskShopPageDTO queryDTO) {
        Long shopBaseId = h2ShopBaseService.queryShopBaseIdByUserId(SecurityUtils.getUserId());
        queryDTO.setShopBaseId(shopBaseId);
        return R.ok(shopSellTaskService.pageByApp(queryDTO));
    }

    @GetMapping("/taskDetail/{id}")
    @Operation(summary = "带货任务详情", parameters = {@Parameter(name = "id", description = "带货任务id")})
    public R<SellTaskDetailVo> taskDetail(@PathVariable Long id) {
        return R.ok(shopSellTaskService.taskDetail(id));
    }


    @GetMapping("/statusList")
    @Operation(summary = "带货任务状态集合")
    public R<List<Map<String, Object>>> statusList() {
        return R.ok(EnumListUtil.enumToListMap(ShopSellTaskStatus.class));
    }


//    @GetMapping("/taskDetail/{id}")
//    @Operation(summary = "带货任务结算详情", parameters = {@Parameter(name = "id", description = "带货任务id")})
//    public R<SellTaskSettlementDetailVo> taskDetail(@PathVariable Long id) {
//        return R.ok(shopSellTaskService.taskDetail(id));
//    }



}
